/**
 * work_status_code
 * 待转正          7
 * 顺利转正         1
 * 延期转正         8
 * 不预转正         9
 * @param defaultParams
 */


function main(defaultParams) {
    let self = this;
    debugger
    self.$$("text_w4a1t").$$setValue(defaultParams.name);
    api.EXEC_FORMULA("TREE_QUERY_CHILDRENS('2c415f80-45bc-40d5-bc69-258c0a029175','" + defaultParams.id + "',['unit_id'])").then((res) => {

        let pageTableList = self.$$("page_widget_list_a9wyvj");
        let pageTableList1 = self.$$("page_widget_list_6wbsnk");

        if (pageTableList && pageTableList.dataEngine && pageTableList.dataEngine.state) {
            const tableComp = pageTableList.dataEngine.state.getElement("table_4w2els");
            const tableComp1 = pageTableList1.dataEngine.state.getElement("table_49acl4");
            tableComp.loading = true;
            tableComp1.loading = true;

            if (tableComp) {

                selectByUnitId(pageTableList, res.result, '0bbd3112-35c4-4013-949c-22ffcf0f7b3e')
                selectByUnitId(pageTableList1, res.result, 'c7049cd0-8add-4d00-a92b-af666cd2538f')


                tableComp.onRefresh();
                tableComp1.onRefresh();
            }
        }

    }).catch(err => {
        self.$message.error(err.message); // 显示错误提示信息
    });
}



/**
 * 通过部门进行过滤
 * @param {*} pageTableList
 * @param {*} unit_id
 * @param fieldValue
 */
function selectByUnitId(pageTableList, unit_id, fieldValue) {

    var members = pageTableList.dataEngine.state.layout.props.dataSet.filterData.filter.members

    members = members.filter(function (item) {
        return item.uniqueIdentify !== "unitIdFilter";
    });

    members.push({
        "uniqueIdentify": "unitIdFilter",
        field: fieldValue,
        fieldName: "unit_id",
        "fieldType": "TYPE_INTEGER",
        valueType: "Constant",
        values: unit_id || [],
        value: "",
        operate: "In", // 范围查询
        className: "Single",
        treeUnitIdFiter: "1"
    });
    var filter = {
        "combine": "And",
        "className": "List",
        "members": members
    };

    pageTableList.dataEngine.state.layout.props.dataSet.filterData = {
        "enabled": true,
        "filter": filter,
        "filterType": "FILTER",
        "rawCondition": {},
        "rawFormula": ""
    }

}



function main() {
    // 获取页面树实例
    var pageTreeEle = this.$$element("page_tree_1ap4be");
    // 获取树渲染实例
    var treeRenderEle = pageTreeEle.$$getRenderElement();
    // 获取当前树实例
    var treePanelEle = treeRenderEle.$$getTreeElement();
    // 获取第一个节点
    var firstNode = treePanelEle.$$getRootNode()[0].id;
    treePanelEle.$$clickNode({ key: firstNode });
}




function main() {

    let pageTreeEle = this.$$("page_tree_1ap4be");

    pageTreeEle.$children[0].$$setExtraParams({
        workStatusCode: '1,7'
    })

    let treeComp = pageTreeEle.dataEngine.state.getElement("tree_panel_78vxbg");
    if (treeComp) {
        treeComp.$$refreshData();
    }

}


function onTabClick(tab) {
    let approvalTypeCodeValue = '';
    if (tab == 2) {
        approvalTypeCodeValue = '3';
    } else {
        approvalTypeCodeValue = null;
    }
    let pageTreeEle = this.$$("page_tree_254tp8");

    pageTreeEle.$children[0].$$setExtraParams({
        workStatusCode: '1,7',
        approvalTypeCode: approvalTypeCodeValue
    })
    let treeComp = pageTreeEle.dataEngine.state.getElement("tree_panel_78vxbg");
    if (treeComp) {
        treeComp.$$refreshData();
    }

}
